package com.hdjk.view.callback;

import com.hdjk.view.entity.SellResult;
import com.lst.projectlib.entity.Msg;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import okhttp3.Response;

/**
 * Created by Admin on 2017/10/25.
 */

public abstract class SellResultCallback extends MsgCallBack {
    @Override
    public Msg parseNetworkResponse(Response response, int id)
            throws Exception {
        Msg msg = super.parseNetworkResponse(response, id);
        JSONObject json = (JSONObject) msg.getData();
        if (json != null) {
            JSONArray object = json.getJSONArray("sellResult");
            List<SellResult> list = new ArrayList<>();
            if (object != null) {
                for (int i = 0; i < object.length(); i++) {
                    JSONObject obj = object.getJSONObject(i);
                    SellResult entity = new SellResult();
                    if (!json.isNull("merchantNumber")) {
                        entity.setMerchantNumber(json.getString("merchantNumber"));
                    }
                    if (!obj.isNull("contractNumber")) {
                        entity.setContractNumber(obj.getString("contractNumber"));
                    }
                    if (!obj.isNull("expectedCofirmedDate")) {
                        entity.setExpectedCofirmedDate(obj.getString("expectedCofirmedDate"));
                    }
                    if (!obj.isNull("expectedDealDate")) {
                        entity.setExpectedDealDate(obj.getString("expectedDealDate"));
                    }
                    if (!obj.isNull("fundCode")) {
                        entity.setFundCode(obj.getString("fundCode"));
                    }
                    if (!obj.isNull("fundName")) {
                        entity.setFundName(obj.getString("fundName"));
                    }
                    if (!obj.isNull("orderDate")) {
                        entity.setOrderDate(obj.getString("orderDate"));
                    }
                    if (!obj.isNull("portfolioId")) {
                        entity.setPortfolioId(obj.getString("portfolioId"));
                    }
                    if (!obj.isNull("reason")) {
                        entity.setReason(obj.getString("reason"));
                    }
                    if (!obj.isNull("transactionDate")) {
                        entity.setTransactionDate(obj.getString("transactionDate"));
                    }
                    if (!obj.isNull("transactionStatus")) {
                        entity.setTransactionStatus(obj.getString("transactionStatus"));
                    }
                    if (!obj.isNull("transactionType")) {
                        entity.setTransactionType(obj.getString("transactionType"));
                    }
                    list.add(entity);
                }
                msg.setData(list);
            }
        }
        return msg;
    }
}